<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 13-3-12
 * Time: 下午7:50
 * To change this template use File | Settings | File Templates.
 */

class Login extends MY_Controller
{
    public function index()
    {
        $this->load->view('agent/login');
    }


    public function doLogin()
    {
        $username = $this->input->get_post('username');
        $password = $this->input->get_post('password');


        $url = url('agent').'/Login/index';


        if (empty ($username) || empty ($password))
        {
            echo '<script>alert("用户名或密码为空!");window.location.href="/Login/index";</script>';
            exit;
        }


        $this->load->service('user/service_user_base');
        $data = $this->service_user_base->login($username, $password, USER_TYPE_AGENT);


        if (200 != $data['status'])
        {
            echo '<script>alert("'.$data['msg'].'!");window.location.href="'.$url.'";</script>';
            exit;
        }


        $data = $data['data'];
        $this->load->helper('cookie');
        set_cookie('auth', auth_code("{$data['uid']}\t{$data['uname']}}", 'ENCODE'), 36000);

        $this->uInfo = $data;


        $url = url('agent').'index/index';


        $this->load->helper('url');
        redirect($url);
    }


    public function logout()
    {
        $this->load->helper('cookie');
        $this->load->helper('url');

        delete_cookie('auth');
        $this->load->helper('url');
        redirect(url('agent').'login/index');
    }
}
